In [2]:
from sympy import *
init_printing()
In [3]:
# State
x, y, vx, vy, m = symbols('x y vx vy m')
r = Matrix([x, y])
v = Matrix([vx, vy])
s = Matrix([r, v, [m]])
# Control
u, theta = symbols('u theta')
# Parameters
c1, c2, c3, g, a = symbols('c1 c2 c3 g a')
In [10]:
# State Dynamics
vnorm = v.norm()
vhat = v/vnorm
print vhat
dx = vx
dy = vy
dvx = c1*u/m*cos(theta) - c3*(vnorm**2)*vhat[0]/m
dvy = c1*u/m*sin(theta) - g - c3*(vnorm**2)*vhat[1]/m
dm = -c1*u/c2
ds = Matrix([dx, dy, dvx, dvy, dm])
In [ ]:
# Homotopic Cost Lagrangian
L = a*c1 / c2 * u + (1-a) * c1**2 /c2 * u**2
In [ ]:
# Hamiltonian
H = l.dot(ds) + L
In [ ]:
# Costate Dynamics
dl = -Matrix([diff(H, i) for i in s])
dl
In [ ]: